<?php

// 获取项目信息
// GET project.data.get

namespace app\api\resource\project;
use think\Db;

class Get
{
    // 方法
    public $_method = ['GET'];
    // 前置
    // public $_pre    = ['login'];
    public $_pre    = [];
    // 描述
    public $_description = '获取项目信息';
    // 参数
    public $_param  = [
        'project_id' => '项目主键',
        'model'      => '获取模式,0-简单数据(默认)|1-完成数据(含运营数据)',
    ];
    // 返回
    public $_return = [
        200 => '获取成功',
        422 => '请求参数不合法',
    ];

    public function run(&$request)
    {
        $model     = $request->get('model/d',0,'abs');
        $projectId = $request->get('project_id/d',0,'abs');
        if (0 == $projectId) return [422,'项目主键必须'];
        
        $project = Db::name('project')->where('id',$projectId)->find();
        if ( !is_null($project) && 1 == $model ) {
            $project['data'] = Db::name('project_data')->where('project_id',$projectId)->find();
        }

        return [200,$project];
    }
}